package top.wyz5204.controller;

import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import top.wyz5204.domain.User;
import top.wyz5204.service.UserService;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author top.wyz5204
 * @since 2023-01-01 22:02
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "hello SpringBoot >> " + (userService == null);
    }

    @GetMapping("/selectAll")
    @ResponseBody
    public String selectAll() {
        List<User> users = userService.selectAll();
        Gson gson = new Gson();
        return gson.toJson(users);
    }

    @GetMapping("/insert")
    @ResponseBody
    public String insert() {
        int result = userService.insert("wyz", 12, "1055115204@qq.com");
        return "插入结果：" + result;
    }
}
